import { createSlice, PayloadAction } from '@reduxjs/toolkit'
import produce from 'immer'
export type pageInfoType = {
  title: string
  desc?: string
  js?: string
  css?: string,
  isPublished?:boolean
}

const INIT_STATE: pageInfoType = { title: '', desc: '', js: '', css: '' }

const pageInfoSlice = createSlice({
  name: 'pageInfo',
  initialState: INIT_STATE,
  reducers: {
    resetPageInfo: (state: pageInfoType, actions: PayloadAction<pageInfoType>): pageInfoType => {
      return actions.payload
    },
    //修改标题
    changePageTitle: produce((draft:pageInfoType,actions:PayloadAction<string>)=>{
      draft.title = actions.payload;
    })

  },
})

export const { resetPageInfo,changePageTitle } = pageInfoSlice.actions
export default pageInfoSlice.reducer
